back to Creeper World
# Immortal-Emitter.crpl
# Created by: nathanaelps
# Created on: 8/22/2020 11:00:49 AM
# ------------------------------------------

$baseEmitAmount:20
$emitDelay:10

$IsFlipped:0
$capturedSecondsAtFullCapacity:10

once @initialize endonce
@pumpCreeper
@enlivenDigitalis

<-emitDelay delay

#-------------------------------

:pumpCreeper
  <-IsFlipped if
    Self CONST_AMMO GetUnitAttribute ->AmmoPool

    <-emitAmount <-baseEmitAmount eq if
      <-AmmoPool 0 gt if
        #freshly recieved ammo
        @setIncapacitated
      endif
    else
      <-AmmoPool 0 lte if
        @setCapacitated
      endif
    endif

    <-emitAmount 0 gt if
      CurrentCoords <-emitAmount SetCreeperNoLower
    else
      Self CONST_AMMO <-AmmoPool <-emitDelay 30.0 div sub SetUnitAttribute
    endif

  else
    Self CONST_HEALTH GetUnitAttribute Self CONST_MAXHEALTH GetUnitAttribute neq if
      @setFlipped
    endif
    CurrentCoords <-emitAmount SetCreeperNoLower
  endif

:enlivenDigitalis
  CurrentCoords GetDigitalisGrowth if
    CurrentCoords 1 SetDigitalis
  endif

:setIncapacitated
  "BLUE" "INFO" "Emitter quelled" "" CurrentPixelCoords ShowGameEventTag
  0 ->emitAmount
  1 ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute

:setCapacitated
  "RED" "INFO" "Emitter awake" "Power to quell" CurrentPixelCoords ShowGameEventTag
  <-baseEmitAmount ->emitAmount
  0 ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY 1 SetUnitAttribute

:setFlipped
  1 ->IsFlipped
  Self CONST_AMMO 0 SetUnitAttribute
  Self CONST_CONNECTABLE 1 SetUnitAttribute
  Self CONST_REQUESTPACKETS 1 SetUnitAttribute
  Self CONST_SHOWAMMOBAR 1 SetUnitAttribute
  Self CONST_CANREQUESTAMMO 1 SetUnitAttribute
  Self CONST_PACKETREQUESTDELAY 1 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
  @setCapacitated
  #@updateImage #already done when we setCapacitated

:initialize
  <-baseEmitAmount ->emitAmount
  @setEmitterName
  Self CONST_COUNTSFORVICTORY 1 SetUnitAttribute
  Self CONST_CREATEPZ 0 SetUnitAttribute
  Self CONST_CONNECTABLE 0 SetUnitAttribute
  Self CONST_SHOWAMMOBAR 0 SetUnitAttribute
  #Self CONST_MAXAMMO 1 <-emitDelay 30.0 div div <-capturedSecondsAtFullCapacity mul SetUnitAttribute
  Self CONST_MAXAMMO <-capturedSecondsAtFullCapacity SetUnitAttribute
  Self CONST_CANREQUESTAMMO 0 SetUnitAttribute
  Self CONST_REQUESTPACKETS 0 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGES 1 SetUnitAttribute
  Self CONST_NULLIFIERDAMAGEAMT 0.1 SetUnitAttribute
  @updateImage

:updateImage
  28 ->ImageStartID
  Self "main" 1.3 1.3 SetImageScale
  <-IsFlipped if
    <-IsDead if
      Self "main" "Custom" <-ImageStartID 3 add Concat SetImage
    else
      Self "main" "Custom" <-ImageStartID 2 add Concat SetImage
    endif
  else
    <-IsDead if
      Self "main" "Custom" <-ImageStartID 1 add Concat SetImage
    else
      Self "main" "Custom" <-ImageStartID 0 add Concat SetImage
    endif
  endif

:setEmitterName
  <-emitAmount " per " <-emitDelay 30.0 div 2 round "s" Concat Concat Concat SetPopupText